#!/usr/bin/python
# -*- encoding: utf-8 -*-
'''
@File    :   1.py
@Time    :   2020/06/24 12:41:34
@Author  :   Malygos_l 
@Version :   1.0
@Contact :   751756061@qq.com
@WebSite :   www.gitee.com/malygos_l
'''
# Start typing your code from here
'''
1  有100个同学的分数：数据请用随机函数生成；
     A 利用多线程程序（比如，5个线程，每个线程负责输出20条记录），快速输出这100个同学的信息；
'''

import threading
import random
import time

mutex = threading.Lock()  #建锁
i = 1


def randgrade(num):
    global i
    x = 0
    for x in range(num):
        mutex.acquire()  #上锁
        grade = random.randint(60, 100)
        print("%d\t%d" % (i, grade))
        i += 1
        time.sleep(1)
        mutex.release()  #解锁


def multithreading():
    for x in range(5):
        t = threading.Thread(target=randgrade, args=(20, ))
        t.start()


def main():
    multithreading()


if __name__ == "__main__":
    main()